Skip to content

Allow overriding /ko-app folder on Linux#1704

Draft
nmdanny wants to merge 3 commits into
ko-build:mainfrom
nmdanny:override-binary-path
Draft

Allow overriding /ko-app folder on Linux#1704
nmdanny wants to merge 3 commits into
ko-build:mainfrom
nmdanny:override-binary-path

Conversation

@nmdanny

@nmdanny nmdanny commented Jul 9, 2026

Copy link
Copy Markdown

Allow overriding the binary folder /ko-app with something else.

Can be useful in some scenarios, e.g, in a Kubernetes environment where a fixed command/path is expected and you can only change the image.

(Only for Linux, I'm not familiar with how Windows containers work or what impact the change might have on them)

Closes #944


Note

Medium Risk
Changes image entrypoint and filesystem layout for every Linux build when overrides are used; default /ko-app is unchanged and behavior is covered by tests, but wrong paths could break deployments that expect a fixed command.

Overview
Adds binaryFolder and binaryPath so Linux images can place the compiled binary somewhere other than /ko-app/<app-name>, while keeping the default when unset.

binaryFolder only changes the directory (app name still derived from the import path); binaryPath sets the full absolute path and wins if both are set (with a log when both are configured). These map through .ko.yaml / KO_BINARYFOLDER and KO_BINARYPATH, BuildOptions, and WithBinaryFolder / WithBinaryPath into the go build path that sets the image entrypoint and binary layer.

On Linux, tarBinary now creates parent directories via parentDirs for arbitrary override paths instead of hard-coding ko-app; Windows layering still uses Files/ko-app. Docs and tests cover defaults, overrides, precedence, and tar directory headers.

Reviewed by Cursor Bugbot for commit b163e5e. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit b163e5e. Configure here.

Comment thread pkg/build/gobuild.go
default:
appDir = "/ko-app"
appPath = path.Join(appDir, appFileName)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows ignores binary path override

High Severity · Logic Bug

When binaryFolder or binaryPath are used, the binary's location within Windows images is customized. However, the Windows entrypoint and PATH environment variable still expect the binary at C:\ko-app. This mismatch causes Windows images to fail to start.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b163e5e. Configure here.

Comment thread pkg/build/gobuild.go
default:
appDir = "/ko-app"
appPath = path.Join(appDir, appFileName)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache omits destination path

High Severity · Logic Bug

When KOCACHE is enabled, the binary layer cache key doesn't include the binary's in-image path, which can now be overridden by binaryFolder or binaryPath. If only the in-image path changes, the cache may return a hit, but the layer's tarball content will be rebuilt with the new path, leading to a digest/blob mismatch.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b163e5e. Configure here.

@nmdanny nmdanny marked this pull request as draft July 9, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renameable binaries / path

1 participant